package logic

import (
	"context"
	"house_srv/models"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseListLogic {
	return &HouseListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 房源展示
func (l *HouseListLogic) HouseList(in *house.HouseListRequest) (*house.HouseListResponse, error) {
	// todo: add your logic here and delete this line
	var houses []models.House
	models.DB.Find(&houses)

	var houseslist []*house.HouseList

	for _, m := range houses {
		list := house.HouseList{
			Title:    m.Title,
			Image:    m.Image,
			Address:  m.Address,
			UserId:   m.UserId,
			MinPrice: float32(m.MinPrice),
			MaxPrice: float32(m.MaxPrice),
			Price:    float32(m.Price),
			Size:     m.Size,
		}
		houseslist = append(houseslist, &list)
	}
	return &house.HouseListResponse{
		List: houseslist,
	}, nil
}
